//
//  UIButton+BackgroundColor.m
//

#import "UIButton+BackgroundColor.h"

@implementation UIButton (BackgroundColor)

- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state
{
    [self setBackgroundImage:[UIButton imageWithColor:backgroundColor] forState:state];
}

- (void)setCornerBackgroundColor:(UIColor *)backgroundColor withRadius:(CGFloat)radius forState:(UIControlState)state
{
    self.layer.cornerRadius = radius;
    self.layer.masksToBounds = YES;
    [self setBackgroundColor:backgroundColor forState:state];
}
- (void)setCornerBorderColor:(UIColor *)Color withRadius:(CGFloat)radius
{
    self.layer.cornerRadius = radius;
    self.layer.masksToBounds = YES;
    self.layer.borderWidth = 1;
    self.layer.borderColor = Color.CGColor;
}
- (void)setCornerWithRadius:(CGFloat)radius
{
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = radius;
}
+ (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

- (void)setButtonTitle:(NSString *)title selectTitle:(NSString *)selectTitle BackgroundColor:(UIColor *)backgroundColor
{
    [self setTitle:title forState:UIControlStateNormal];
    [self setTitle:selectTitle forState:UIControlStateSelected];
    [self setBackgroundColor:backgroundColor forState:UIControlStateNormal];
    [self setTintColor:[UIColor whiteColor]];
}
@end
